package com.koko.service.Impl;

import com.koko.mapper.UserGameMapper;
import com.koko.mapper.UserMapper;
import com.koko.service.UserGameService;
import com.koko.user.entity.UserGame;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserGameServiceImpl implements UserGameService {
    @Autowired
    private UserGameMapper userGameMapper;
    @Autowired
    private UserMapper userMapper;

    /**
     * 通过gameId判断用户是否有此游戏
     * @param userId
     * @param gameId
     * @return
     */
    @Override
    public String isUserHaveGame(Long userId, Long gameId) {
        Integer count = userGameMapper.isUserHaveGame(userId, gameId);
        if (count > 0) {
            return userMapper.getById(userId).getNickname();
        }
        return null;
    }

    /**
     * 用户添加游戏
     * @param userGame
     */
    @Override
    public void addGameForUser(UserGame userGame) {
        userGameMapper.insert(userGame);
    }
}
